package cn.seocoo.platform.version.service.impl;

import cn.seocoo.platform.common.core.text.Convert;
import cn.seocoo.platform.version.domain.AppVersion;
import cn.seocoo.platform.version.mapper.AppVersionMapper;
import cn.seocoo.platform.version.service.IAppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 版本 服务层实现
 * 
 * @author pyh
 * @date 2019-11-15
 */
@Service
public class AppVersionServiceImpl implements IAppVersionService 
{
	@Autowired
	private AppVersionMapper appVersionMapper;

	/**
     * 查询版本信息
     * 
     * @param id 版本ID
     * @return 版本信息
     */
    @Override
	public AppVersion selectAppVersionById(Integer id)
	{
	    return appVersionMapper.selectAppVersionById(id);
	}
	
	/**
     * 查询版本列表
     * 
     * @param appVersion 版本信息
     * @return 版本集合
     */
	@Override
	public List<AppVersion> selectAppVersionList(AppVersion appVersion)
	{
	    return appVersionMapper.selectAppVersionList(appVersion);
	}
	
    /**
     * 新增版本
     * 
     * @param appVersion 版本信息
     * @return 结果
     */
	@Override
	public int insertAppVersion(AppVersion appVersion)
	{
	    return appVersionMapper.insertAppVersion(appVersion);
	}
	
	/**
     * 修改版本
     * 
     * @param appVersion 版本信息
     * @return 结果
     */
	@Override
	public int updateAppVersion(AppVersion appVersion)
	{
	    return appVersionMapper.updateAppVersion(appVersion);
	}

	/**
     * 删除版本对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteAppVersionByIds(String ids)
	{
		return appVersionMapper.deleteAppVersionByIds(Convert.toStrArray(ids));
	}

	/**
	 * @Author pyh
	 * @Description App版本
	 * @Date 2019/11/15
	 * @Param [appVersionTemp]
	 * @return cn.seocoo.platform.version.domain.AppVersion
	 **/
    @Override
	@Transactional(rollbackFor = Exception.class)
    public AppVersion checkVersion(AppVersion appVersionTemp) {
		List<AppVersion> list = appVersionMapper.selectAppVersionList(appVersionTemp);
		if (list == null || list.size() == 0) {
			return new AppVersion();
		}
		return list.get(0);
    }

    /**
     * @Author pyh
     * @Description App上架
     * @Date 2019/11/15
     * @Param [appVersionTemp]
     * @return int
     **/
	@Override
	@Transactional(rollbackFor = Exception.class)
	public int checkPutAway(AppVersion appVersionTemp) {
		List<AppVersion> list = appVersionMapper.selectAppVersionList(appVersionTemp);
		if (list == null || list.size() == 0) {
			return 0;
		}
		return 1;
	}

}
